#ifndef UTIL_H_
#define UTIL_H_
#include <cmath>
#define MINUS_LOG_EPSILON 50
namespace MRFPP{

// helper functions defined in the paper
inline double sigma(double x) {
  if (x > 0) return 1.0;
  else if (x < 0) return -1.0;
  return 0.0;
}

inline double logsumexp(double x, double y, bool flg) 
{
  if (flg) return y;  // init mode
  const double vmin = ( x < y ) ? x : y;
  const double vmax = ( x > y ) ? x : y;
  if (vmax > vmin + MINUS_LOG_EPSILON) 
    return vmax;
  else 
    return vmax + std::log(std::exp(vmin - vmax) + 1.0);
}
}
#endif
